<?php
namespace app\common\model;
use app\common\model\CommonModel;
use think\Db;

class OrderAfter extends CommonModel
{
	/**
	* 生成售后订单信息
	*/
	public function serOrderAfter($data)
	{
		return $this->insert($data);
	}
    /**
    * 连表查询
    */
    public function afterList($where,$limit,$field,$group = 'a.order_after_id')
    {
        return $this->alias('a')
				->join('mps_order_goods g','a.after_goods = g.order_goods_id')
                ->join('mps_order o','a.order_id = o.order_id')
				->where($where)->field($field)
                ->group($group)
                ->order('a.addtime DESC')
                ->paginate($limit);
    }
    /**
    * 订单数量
    */
    public function afterCount($where)
    {
        return $this->alias('a')
				->join('mps_order_goods g','a.after_goods = g.order_goods_id')
                ->join('mps_order o','a.order_id = o.order_id')
				->where($where)->count();
    }
    /**
    * 金额计算
    */
    public function afterSum($where,$field)
    {
        return $this->alias('a')
				->join('mps_order_goods g','a.after_goods = g.order_goods_id')
                ->join('mps_order o','a.order_id = o.order_id')
				->where($where)->sum($field);
    }
    /**
    * 售后单详情
    */
    public function afterInfo($where)
    {
        $item = $this->where($where)->find();
        return empty($item) ? array():$item->toArray();
    }
}
